package com.base.platform.biz;

import com.base.platform.entity.DataAnalyzeMaster;
import com.base.platform.entity.query.DataQuery;
import com.base.platform.mapper.DataAnalyzeMasterMapper;
import com.base.platform.utils.ResponseResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Class DataAnalyzeMasterBiz
 * @Description 数据处理服务
 * @Author lihuibin
 * @Date 2020/12/16 22:01
 * @Version 1.0
 * 更新记录:
 * 更新时间        更新人        更新位置        更新内容
 * 2020/12/16       lihuibin       新建           新建
 */
@Service
public class DataAnalyzeMasterBiz {
    @Resource
    private DataAnalyzeMasterMapper dataAnalyzeMasterMapper;

    public DataAnalyzeMaster queryById(Integer id) {
        return this.dataAnalyzeMasterMapper.selectByPrimaryKey(id);
    }

    public ResponseResult queryList(DataQuery query) {
        if (query.getEnablePage()) {
            PageHelper.startPage(query.getPageNum(),query.getPageSize());
        }
        List<DataAnalyzeMaster> select = this.dataAnalyzeMasterMapper.select(query);
        PageInfo<DataAnalyzeMaster> pageInfo = new PageInfo<>(select);
        return ResponseResult.success(pageInfo);
    }

    public ResponseResult queryAll(DataQuery query){
        if (query.getEnablePage()) {
            PageHelper.startPage(query.getPageNum(),query.getPageSize());
        }
        List<DataAnalyzeMaster> dataAnalyzeMasters = this.dataAnalyzeMasterMapper.selectAll();
        return ResponseResult.success(new PageInfo<>(dataAnalyzeMasters));
    }

    public ResponseResult insert(DataAnalyzeMaster model) {
        int result = this.dataAnalyzeMasterMapper.insertSelective(model);
        if (result > 0) {
            return ResponseResult.success();
        }
        return ResponseResult.fail("添加数据失败",null);
    }

    public ResponseResult update(DataAnalyzeMaster form) {
        int result = this.dataAnalyzeMasterMapper.updateByPrimaryKeySelective(form);
        if (result > 0) {
            return ResponseResult.success();
        }
        return ResponseResult.fail("修改数据失败",null);
    }

    public ResponseResult delete(Integer id) {
        int result = this.dataAnalyzeMasterMapper.deleteById(id);
        if (result > 0) {
            return ResponseResult.success();
        }
        return ResponseResult.fail("删除数据失败",null);
    }
}
